﻿ @{
    ViewData["Title"] = "MyEventView";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@* <script src="~/layui/jquery-3.3.1.js"></script> *@

<div style="margin:60px">    
    <div class="layui-input-inline">
        <div class="layui-form layui-row layui-col-space16">
            <label class="layui-form-label" style="margin-top:10px">事件类型：</label>
            <div class="layui-col-md6" style="width:300px">                
                <select id="EventTypeID">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
    </div>
    
    <div class="layui-input-inline">
        <div class="layui-form layui-row layui-col-space16">
            <label class="layui-form-label" style="margin-top:10px">事件级别：</label>
            <div class="layui-col-md6" style="width:300px">                
                <select id="EventLevelID">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
    </div>
    <br />
    <div class="layui-input-inline">
        <div class="layui-form layui-row layui-col-space16">
            <label class="layui-form-label" style="margin-top:10px">事件来源：</label>
            <div class="layui-col-md6" style="width:300px">
                <select id="EventSourceID">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
    </div>
    <br />
    <div class="layui-inline" style="text-align:center">
        <button id="searchbtn" type="button" class="layui-btn" style="background-color:#1e9fff">搜&emsp;索</button>
        <button type="button" class="layui-btn" style="background-color:#ff5722">重&emsp;置</button>
    </div>
    
    <table id="ID-table-demo-setRowChecked"></table>

    @* <div id="pagesbox"></div> *@

    <!--添加的弹出层-->
   @*  <div id="add-main" style="display: none;">
        <div>
            <div style="float:left;margin-left:20px">
                <span id="Id" style="display:none"></span>
                <label id="BindId">menuName</label>
            </div>
             <label id="newid">newmenuName</label> 
            <div style="float:left;margin-left:20px" id="ID-tree-demo-showCheckbox"></div>

            <input type="hidden" name="permissionId" />
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saves">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary" id="closeBtn">重置</button>
                </div>
            </div>
        </div>
    </div> *@

    <script>
        layui.use(['table', 'laypage', 'layer', 'form'], function () {
            var table = layui.table;
            var $ = layui.jquery;
            var form = layui.form;
            function GetMyEventData() {

                //获取查询条件
                var EventType = $('#EventTypeID').val();
                var EventLevel = $('#EventLevelID').val();
                var EventSource = $('#EventSourceID').val();
                //ajax后台交互
                $.ajax({
                    url: 'http://8.140.245.229:8000/SingleRead/api/EventY/GetEmergency',
                    type: 'get',
                    dataType: 'json',
                    //参数
                    data: {
                        EventType: EventType,
                        EventSource: EventSource,
                        EventLevel: EventLevel,
                    },
                    success: function (res) {
                        //渲染表格数据
                        layui.use(['table'], function () {
                            var table = layui.table;
                            table.render({
                                //挂载的表格id
                                elem: '#ID-table-demo-setRowChecked',
                                cols: [[
                                    { type: 'numbers', title: '序号', width: 120, align: 'center' },
                                    { field: 'EventDesc', title: '事件描述', width: 120, align: 'center' },
                                    {
                                        field: 'EventLevel', title: '事件级别', width: 120, align: 'center',
                                        templet: function (d) {
                                            if (d.EventLevel == 1) {
                                                return '<span>一般</span>'
                                            } else if (d.EventLevel == 2) {
                                                return '<span>紧急</span>'
                                            }
                                        }
                                    },
                                    {
                                        field: 'ReportDate', title: '上报时间', width: 120, align: 'center',
                                        templet: function (data) { return data.ReportDate.substring(0, 16).replace("T", " ") }
                                    },
                                    {
                                        field: 'ArriveDate', title: '到达时间', width: 120, align: 'center',
                                        templet: function (data) { return data.ArriveDate.substring(0, 16).replace("T", " ") }
                                    },
                                    {
                                        field: 'EndTime', title: '处理截止时间', width: 120, align: 'center',
                                        templet: function (data) { return data.EndTime.substring(0, 16).replace("T", " ") }
                                    },
                                    {
                                        field: 'WarningState', title: '预警状态', width: 120, align: 'center',
                                        templet: function (d) {
                                            if (d.WarningState == 1) {
                                                return '<i class="layui-icon layui-icon-circle-dot" style="font-size: 20px; color: #16b777;"></i>'
                                            } else if (d.WarningState == 2) {
                                                return '<i class="layui-icon layui-icon-circle-dot" style="font-size: 20px; color: #ff5722"></i>'
                                            }
                                        }
                                    },
                                    {
                                        field: 'NodeTypeEnum', title: '当前节点', width: 120, align: 'center', templet: function (d) {
                                            if (d.NodeTypeEnum == 1) {
                                                return '<span>立案审核</span>'
                                            } else if (d.NodeTypeEnum == 2) {
                                                return '<span>现场核实</span>'
                                            } else if (d.NodeTypeEnum == 3) {
                                                return '<span>案件核查</span>'
                                            } else if (d.NodeTypeEnum == 4) {
                                                return '<span>案件处置</span>'
                                            }
                                        }
                                    },
                                    { title: '操作', width: 120, align: 'center', templet: '#barDemo', fixed: 'right', unresize: true },
                                ]],
                                data: res
                            })
                        })
                    }
                })
            }
            //事件类型
            function GetEventType() {
                $.ajax({
                    url: "http://8.140.245.229:8000/SingleRead/api/EventY/GetEventType",
                    async: false,
                    type:"get",
                    success: function (res) {
                        var select = $("#EventTypeID");
                        $.each(res, function (index, item) {
                            select.append($('<option>').val(item.name).text(item.name))
                        })
                        layui.form.render('select');
                    }
                })
            }

            //事件级别
            function GetEventLevel() {
                $.ajax({
                    url: "http://8.140.245.229:8000/SingleRead/api/EventY/GetEventLevel",
                    async: false,
                    type: "get",
                    success: function (res) {
                        var select = $("#EventLevelID");
                        $.each(res, function (index, item) {
                            select.append($('<option>').val(item.name).text(item.name))
                        })
                        layui.form.render('select');
                    }
                })
            }

            //事件来源
            function GetEventSource() {
                $.ajax({
                    url: "http://8.140.245.229:8000/SingleRead/api/EventY/GetEventSource",
                    async: false,
                    type: "get",
                    success: function (res) {
                        var select = $("#EventSourceID");
                        $.each(res, function (index, item) {
                            select.append($('<option>').val(item.name).text(item.name))
                        })
                        layui.form.render('select');
                    }
                })
            }

            $(function () {
                // 初始化加载数据
                GetMyEventData();
                GetEventType();
                GetEventLevel();
                GetEventSource();
            })

            $('#searchbtn').on('click', function () {
                GetMyEventData();
            });

            // 监听表单提交
            form.on('submit(save)', function (data) {

                var formData = {
                    RoleName: $("#roleName").val(),
                    RoleRemark: $("#roleRemark").val(),
                    // NewEarTag: $("input[name='newEarTag']").val(),
                    // Reason: $("#reasonsAdd").val(),
                    CreateBy: "张三",
                    CreateDate: Date.now,
                };

                $.ajax({
                    url: 'http://8.140.245.229:8000/AuthorizationPeopleSetRout/api/Employee/AddRole', // 替换为您的后端API接口地址
                    type: 'post',
                    data: JSON.stringify(formData),
                    contentType: 'application/json',
                    success: function (res) {
                        
                        if (res > 0) {
                            alert("添加成功！");
                            location.href = '/Role/ShowRole'
                            // layer.msg(res.msg, {icon: 1 });
                            // setTimeout(function () {
                            //     location.href = '/Role/ShowRole'
                            // }, 1000)
                        } else {
                            //layer.msg(res.msg, { icon: 2 });
                            alert("添加失败！");
                        }
                    },
                    error: function () {
                        layer.msg('网络错误，请稍后重试', { icon: 2 });
                    }
                });
                return false; // 阻止表单跳转
            });  

        });
        </script>
    
</div>
<script type="text/html" id="barDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit">查看</i></a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">撤回</a>
    </div>
</script>
<script type="text/javascript">
    var a_idx = 0;
    jQuery(document).ready(function ($) {
        $("body").click(function (e) {
            var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善");
            var $i = $("<span/>").text(a[a_idx]);
            a_idx = (a_idx + 1) % a.length;
            var x = e.pageX,
                y = e.pageY;
            $i.css({
                "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
                "top": y - 20,
                "left": x,
                "position": "absolute",
                "font-weight": "bold",
                "color": "#ff6651"
            });
            $("body").append($i);
            $i.animate({
                "top": y - 180,
                "opacity": 0
            },
                1500,
                function () {
                    $i.remove();
                });
        });
    });
</script>